<template>
	<view class="box">
		<!-- 导航栏 -->
		<!-- <view class="search_box">
    	<view class="flex_box aic">
    		<view class="re mr20">
    			<image src="/static/icon_arrow_1.png" @tap="back" class="vt img6"></image>   		</view>
    		<view class="re item" style="font-weight: bolder;text-align: center;font-size: larger;">{{title}}</view>
    	</view>
    </view> -->
		<!-- 导航栏 -->

		<view class="menu_content_box_page" v-if="beVideo" v-show="beVideo" >
			<video :src="url" style="width: 100%;" :controls="true" :autoplay="true"></video>
			
		</view>
		<view class="menu_content_box_page" v-if="!beVideo" v-show="!beVideo" >
			<web-view v-show="!beVideo" v-if="!beVideo" :src="html"> </web-view>
		</view>

	</view>
</template>
<script>
	import {
		toast,
		showLoading,
		hideLoading
	} from '@/utils/toast.js';
	import {
		getDatumDetailPageApi,
		getDatumUrlApi,
		getVideoUrlApi,
		getHtmlContentApi
	} from '@/http/api.js';

	export default {
		data() {
			return {
				html: '',
				url: '',
				id: 0,
				beVideo: true,
				userId: uni.getStorageSync('userId'),
				title: ''
			}
		},
		onLoad(options) {
			console.log(options, 99999);
			if (!options.id) {
				toast('参数不正确！');
			}
			this.id = options.id;
			this.title = options.title;
			if (options.beVideo) {
				this.beVideo = options.beVideo;
			}
			if (this.title) {
				uni.setNavigationBarTitle({
					title: this.title
				})
			}
			this.getDatumDetailPage();

			// #ifdef APP-PLUS
			var that = this;
			that.statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
			var w = plus.webview.create(this.weburl, 'id', {
				// top: uni.getSystemInfoSync().statusBarHeight + 44 ,//放置在titleNView下方。如果还想在webview上方加个地址栏的什么的，可以继续降低TOP值
				//因为设置top之后 webview的高度依然不变会往下移 底部会被遮住  所以设置一下高度
				//  height: uni.getSystemInfoSync().windowHeight - 44 - uni.getSystemInfoSync().statusBarHeight,
				titleNView: {
					"autoBackButton": true,
					"type": "default",
					"backgroundColor": "#FFFFFF",
					titleText: this.title
				}
			}, {
				preload: 'preload webview'
			}); // 可直接通过以下方法获取preload值
			var currentWebview = this.$mp.page.$getAppWebview() //获取当前页面的webview对象
			currentWebview.append(w); //一定要append到当前的页面里！！！才能跟随当前页面一起做动画，一起关闭
			// #endif
		},
		methods: {
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			getDatumDetailPage() {
				let that = this;
				showLoading('加载中');
				getDatumDetailPageApi({
					id: this.id,
					userId: this.userId
				}).then(res => {
					that.detail = res.data;
					that.beVideo = res.data.beVideo;
					if (that.detail.beVideo) {
						that.getVideoUrl();
					} else {
						that.getHtmlContent();
					}
				}).catch(err => {
					toast(err.msg);
					hideLoading();
				})
			},

			getVideoUrl() {
				let that = this;
				showLoading('加载中');
				getVideoUrlApi({
					userId: uni.getStorageSync('userId'),
					id: this.id
				}).then(res => {
					let url = res.data;
					that.url = url;
					hideLoading();
				}).catch(err => {
					hideLoading();
				})
			},

			getHtmlContent() {
				let that = this;
				showLoading('加载中');
				getHtmlContentApi({
					userId: uni.getStorageSync('userId'),
					id: this.id
				}).then(res => {
					that.html = res.data;
					console.log(that.html)
					hideLoading();
				}).catch(err => {
					hideLoading();
				})
			},

			preview(src, e) {
				// do something
			},
			navigate(href, e) {
				// do something
			}
		}
	}
</script>

<style>
	.menu_content_box_page {
		position: relative;
		background-color: #f7f6f6;
		padding-top: 177rpx;
	}

	.search_box {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		padding: 85rpx 24rpx 25rpx;
		background-color: #fff;
		z-index: 3;
	}
</style>
